package com.coin.controller;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.coin.exchange.ok.vo.OkAccountRecordsRequestVO;
import com.coin.exchange.ok.vo.OkBatchTradeRequestVO;
import com.coin.exchange.ok.vo.OkCancelOrderRequestVO;
import com.coin.exchange.ok.vo.OkCancelWithdrawRequestVO;
import com.coin.exchange.ok.vo.OkFundsTransferRequestVO;
import com.coin.exchange.ok.vo.OkFutureBatchTradeVO;
import com.coin.exchange.ok.vo.OkFutureCancelVO;
import com.coin.exchange.ok.vo.OkFutureDepthVO;
import com.coin.exchange.ok.vo.OkFutureDevolveVO;
import com.coin.exchange.ok.vo.OkFutureExplosiveVO;
import com.coin.exchange.ok.vo.OkFutureHoldAmountVO;
import com.coin.exchange.ok.vo.OkFutureKlineVO;
import com.coin.exchange.ok.vo.OkFutureOrderInfoVO;
import com.coin.exchange.ok.vo.OkFuturePositionVO;
import com.coin.exchange.ok.vo.OkFuturePriceLimitVO;
import com.coin.exchange.ok.vo.OkFutureTickerVO;
import com.coin.exchange.ok.vo.OkFutureTradeVO;
import com.coin.exchange.ok.vo.OkFutureTradesHisVO;
import com.coin.exchange.ok.vo.OkFutureTradesVO;
import com.coin.exchange.ok.vo.OkFutureUserinfoVO;
import com.coin.exchange.ok.vo.OkKlineRequestVO;
import com.coin.exchange.ok.vo.OkOrderHistoryRequestVO;
import com.coin.exchange.ok.vo.OkOrderInfoRequestVO;
import com.coin.exchange.ok.vo.OkOrdersInfoRequestVO;
import com.coin.exchange.ok.vo.OkTradeRequestVO;
import com.coin.exchange.ok.vo.OkTradesRequestVO;
import com.coin.exchange.ok.vo.OkUserinfoRequestVO;
import com.coin.exchange.ok.vo.OkWalletInfoRequestVO;
import com.coin.exchange.ok.vo.OkWithdrawInfoRequestVO;
import com.coin.exchange.ok.vo.OkWithdrawRequestVO;
import com.coin.exchange.okex.rest.future.IFutureRestApi;
import com.coin.exchange.okex.rest.stock.IStockRestApi;
import com.coin.framework.bean.ResultForm;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/rest/okex")
public class OkexController {

	private static Logger logger = LoggerFactory.getLogger(OkexController.class);
	
	@Autowired
	private IStockRestApi iStockRestApi;

	@Autowired
	private IFutureRestApi iFutureRestApi;
	
	@ApiOperation(value = "获取币币行情数据")
	@RequestMapping(value = "/getTicker", method = RequestMethod.POST)
	public ResultForm<?> getTicker(@RequestBody String symbol) {
		ResultForm<?> resultForm = null;
//		String symbol = jsonObject.getString("symbol");
		try {
			String res = iStockRestApi.ticker(symbol);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取币币市场深度")
	@RequestMapping(value = "/getDepth", method = RequestMethod.POST)
	public ResultForm<?> getDepth(@RequestBody String symbol) {
		ResultForm<?> resultForm = null;
//		String symbol = jsonObject.getString("symbol");
		try {
			String res = iStockRestApi.depth(symbol);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取币币交易信息")
	@RequestMapping(value = "/getTrades", method = RequestMethod.POST)
	public ResultForm<?> getTrades(@RequestBody @Valid OkTradesRequestVO vo) {
		ResultForm<?> resultForm = null;
		String symbol = vo.getSymbol();
		String since = vo.getSince();
		try {
			String res = iStockRestApi.trades(symbol, since);
			JSONArray resultObject = JSONArray.parseArray(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取币币K线数据")
	@RequestMapping(value = "/getKline", method = RequestMethod.POST)
	public ResultForm<?> getKline(@RequestBody @Valid OkKlineRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iStockRestApi.kline(vo);
			JSONArray resultObject = JSONArray.parseArray(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取用户信息")
	@RequestMapping(value = "/getUserinfo", method = RequestMethod.POST)
	public ResultForm<?> getUserinfo(@RequestBody @Valid OkUserinfoRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String api_key = vo.getApi_key();
			String secret_key = vo.getSecret_key();
			String res = iStockRestApi.userinfo(api_key, secret_key);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "下单交易")
	@RequestMapping(value = "/trade", method = RequestMethod.POST)
	public ResultForm<?> trade(@RequestBody @Valid OkTradeRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String api_key = vo.getApi_key();
			String secret_key = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String type = vo.getType();
			String price = vo.getPrice();
			String amount = vo.getAmount();
			String res = iStockRestApi.trade(api_key, secret_key, symbol, type, price, amount);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "批量下单")
	@RequestMapping(value = "/batchTrade", method = RequestMethod.POST)
	public ResultForm<?> batchTrade(@RequestBody @Valid OkBatchTradeRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String api_key = vo.getApi_key();
			String secret_key = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String type = vo.getType();
			String orders_data = vo.getOrders_data();
			String res = iStockRestApi.batch_trade(api_key, secret_key, symbol, type, orders_data);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "撤销订单")
	@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
	public ResultForm<?> cancelOrder(@RequestBody @Valid OkCancelOrderRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String api_key = vo.getApi_key();
			String secret_key = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String order_id = vo.getOrder_id();
			String res = iStockRestApi.cancel_order(api_key, secret_key, symbol, order_id);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取用户的订单信息")
	@RequestMapping(value = "/getOrderInfo", method = RequestMethod.POST)
	public ResultForm<?> getOrderInfo(@RequestBody @Valid OkOrderInfoRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String api_key = vo.getApi_key();
			String secret_key = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String order_id = vo.getOrder_id();
			String res = iStockRestApi.order_info(api_key, secret_key, symbol, order_id);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "批量获取用户订单")
	@RequestMapping(value = "/getOrdersInfo", method = RequestMethod.POST)
	public ResultForm<?> getOrdersInfo(@RequestBody @Valid OkOrdersInfoRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String api_key = vo.getApi_key();
			String secret_key = vo.getSecret_key();
			String type = vo.getType();
			String symbol = vo.getSymbol();
			String order_id = vo.getOrder_id();
			String res = iStockRestApi.orders_info(api_key, secret_key, type, symbol, order_id);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取历史订单信息")
	@RequestMapping(value = "/getOrderHistory", method = RequestMethod.POST)
	public ResultForm<?> getOrderHistory(@RequestBody @Valid OkOrderHistoryRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String api_key = vo.getApi_key();
			String secret_key = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String status = vo.getStatus();
			String current_page = vo.getCurrent_page();
			String page_length = vo.getPage_length();
			String res = iStockRestApi.order_history(api_key, secret_key, symbol, status, current_page, page_length);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "提币BTC/LTC/ETH/ETC/BCH")
	@RequestMapping(value = "/withdraw", method = RequestMethod.POST)
	public ResultForm<?> withdraw(@RequestBody @Valid OkWithdrawRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iStockRestApi.withdraw(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "取消提币BTC/LTC/ETH/ETC/BCH")
	@RequestMapping(value = "/cancelWithdraw", method = RequestMethod.POST)
	public ResultForm<?> cancelWithdraw(@RequestBody @Valid OkCancelWithdrawRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iStockRestApi.cancel_withdraw(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "查询提币BTC/LTC/ETH/ETC/BCH信息")
	@RequestMapping(value = "/getWithdrawInfo", method = RequestMethod.POST)
	public ResultForm<?> getWithdrawInfo(@RequestBody @Valid OkWithdrawInfoRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iStockRestApi.withdraw_info(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取用户提现/充值记录")
	@RequestMapping(value = "/getAccountRecords", method = RequestMethod.POST)
	public ResultForm<?> getAccountRecords(@RequestBody @Valid OkAccountRecordsRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iStockRestApi.account_records(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "资金划转")
	@RequestMapping(value = "/fundsTransfer", method = RequestMethod.POST)
	public ResultForm<?> fundsTransfer(@RequestBody @Valid OkFundsTransferRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iStockRestApi.funds_transfer(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取用户钱包账户信息")
	@RequestMapping(value = "/getWalletInfo", method = RequestMethod.POST)
	public ResultForm<?> getWalletInfo(@RequestBody @Valid OkWalletInfoRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iStockRestApi.wallet_info(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}
///////////////////////////////////////////////////////////////////////////////////////////////////
	@ApiOperation(value = "获取合约行情")
	@RequestMapping(value = "/futureTicker", method = RequestMethod.POST)
	public ResultForm<?> futureTicker(@RequestBody @Valid OkFutureTickerVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_ticker(vo.getSymbol(), vo.getContract_type());
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约指数信息")
	@RequestMapping(value = "/futureIndex", method = RequestMethod.POST)
	public ResultForm<?> futureIndex(@RequestBody String symbol) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_index(symbol);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "期货交易记录")
	@RequestMapping(value = "/futureTrades", method = RequestMethod.POST)
	public ResultForm<?> futureTrades(@RequestBody @Valid OkFutureTradesVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_trades(vo.getSymbol(), vo.getContract_type());
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约深度信息")
	@RequestMapping(value = "/futureDepth", method = RequestMethod.POST)
	public ResultForm<?> futureDepth(@RequestBody @Valid OkFutureDepthVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_depth(vo.getSymbol(), vo.getContract_type());
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取美元人民币汇率")
	@RequestMapping(value = "/futureExchangeRate", method = { RequestMethod.GET, RequestMethod.POST })
	public ResultForm<?> futureExchangeRate() {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.exchange_rate();
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取交割预估价", notes = "交割预估价只有交割前三小时返回")
	@RequestMapping(value = "/futureEstimatedPrice", method = RequestMethod.POST)
	public ResultForm<?> futureEstimatedPrice(@RequestBody String symbol) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_estimated_price(symbol);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约K线信息")
	@RequestMapping(value = "/futureKline", method = RequestMethod.POST)
	public ResultForm<?> futureKline(@RequestBody @Valid OkFutureKlineVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_kline(vo);
			JSONArray resultObject = JSONArray.parseArray(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取当前可用合约总持仓量")
	@RequestMapping(value = "/futureHoldAmount", method = RequestMethod.POST)
	public ResultForm<?> futureHoldAmount(@RequestBody @Valid OkFutureHoldAmountVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_hold_amount(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约最高限价和最低限价")
	@RequestMapping(value = "/futurePriceLimit", method = RequestMethod.POST)
	public ResultForm<?> futurePriceLimit(@RequestBody @Valid OkFuturePriceLimitVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_price_limit(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "取消合约订单")
	@RequestMapping(value = "/futureCancel", method = RequestMethod.POST)
	public ResultForm<?> futureCancel(@RequestBody @Valid OkFutureCancelVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_cancel(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "合约下单")
	@RequestMapping(value = "/futureTrade", method = RequestMethod.POST)
	public ResultForm<?> futureTrade(@RequestBody @Valid OkFutureTradeVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_trade(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约交易历史")
	@RequestMapping(value = "/futureTradesHistory", method = RequestMethod.POST)
	public ResultForm<?> futureTradesHistory(@RequestBody @Valid OkFutureTradesHisVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_trades_history(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "批量下单")
	@RequestMapping(value = "/futureBatchTrade", method = RequestMethod.POST)
	public ResultForm<?> futureBatchTrade(@RequestBody @Valid OkFutureBatchTradeVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_batch_trade(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约账户信息(全仓)")
	@RequestMapping(value = "/futureUserinfo", method = RequestMethod.POST)
	public ResultForm<?> futureUserinfo(@RequestBody @Valid OkFutureUserinfoVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_userinfo(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取逐仓合约账户信息")
	@RequestMapping(value = "/futureUserinfo4fix", method = RequestMethod.POST)
	public ResultForm<?> futureUserinfo4fix(@RequestBody @Valid OkFutureUserinfoVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_userinfo_4fix(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "用户持仓查询")
	@RequestMapping(value = "/futurePosition", method = RequestMethod.POST)
	public ResultForm<?> futurePosition(@RequestBody @Valid OkFuturePositionVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_position(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "逐仓用户持仓查询")
	@RequestMapping(value = "/futurePosition4fix", method = RequestMethod.POST)
	public ResultForm<?> futurePosition4fix(@RequestBody @Valid OkFuturePositionVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_position_4fix(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约订单信息")
	@RequestMapping(value = "/futureOrderInfo", method = RequestMethod.POST)
	public ResultForm<?> futureOrderInfo(@RequestBody @Valid OkFutureOrderInfoVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_order_info(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "获取合约爆仓单")
	@RequestMapping(value = "/futureExplosive", method = RequestMethod.POST)
	public ResultForm<?> futureExplosive(@RequestBody @Valid OkFutureExplosiveVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_explosive(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "个人账户资金划转")
	@RequestMapping(value = "/futureDevolve", method = RequestMethod.POST)
	public ResultForm<?> futureDevolve(@RequestBody @Valid OkFutureDevolveVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String res = iFutureRestApi.future_devolve(vo);
			JSONObject resultObject = JSONObject.parseObject(res);
			resultForm = ResultForm.createSuccessResultForm(resultObject, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

}
